Random Desktop 0.2: Picks a random desktop pattern and a random desktop picture from any number of pictures in a specified folder.
Copyright (C) 1999-2000 Gordon Worley.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
For a copy of the GNU General Public License, visit <http://www.gnu.org/> or write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330, Boston, MA 02111-1307, USA.
To contact me, please visit my Web site at <http://www.rbisland.cx/> or e-mail me at <redbird@rbisland.cx>.
History:
0.2 - Now uses repeating in randPatt() rather than recursion. Duh!
0.1.2 - Added error handling to randPict() so that the script won't just stop if it tries to give Desktop Pictures a nonpicture as a picture
0.1.1 - Fixed a bug with the random numbers (I had to start from one rather than zero) and stopped rounding, since it turns out that random number returns an integer
0.1 - Added support for random pictures and created handlers for the two desktop setting operations
0.0 - Initial release.
*)
on run
randPatt()
randPict()
tell application "Desktop Pictures" to quit
end run
on randPatt()
set keep_repeating to true
repeat while keep_repeating is true
try
tell application "Desktop Pictures" to set desktop pattern to (random number from 1 to 128) --128 is the largest possible value for small integer, which is what set desktop picture takes
set keep_repeating to false
on error --the random number was out of range
--pass
end try
end repeat
end randPatt
on randPict()
tell application "Finder" to set desktopPictFolder to startup disk's folder "Apple Extras"'s folder "Sample Desktop Pictures" --this can point to any folder with just pictures in it that Desktop Pictures can read
set desktopPictFolderItems to list folder desktopPictFolder
try
tell application "Desktop Pictures" to set desktop picture to alias ((desktopPictFolder as string) & desktopPictFolderItems's item (random number from 1 to (length of desktopPictFolderItems))) positioning centered alignment none
on error --the file was probably not a picture that Desktop Pictures could read
--you could tell the user here about what happened, but as long as a picture gets set they probably won't care